class MultiHopConnection
  def initialize(multi_hop_flight)
    @m_flight = multi_hop_flight
    @m_connections = []
  end

  def add_connection(connection)
    @m_connections << connection
  end

  def m_flight
    return @m_flight
  end
  # @return a clone of the list with the connections
  def connections
    return @m_connections.clone
  end

  def from
    @m_flight.from
  end

  def destionation
    @m_flight.destination
  end

  def departure_date
    return @m_connections.first.departure_date
  end

  def departure
    return @m_connections.first.departure
  end
  
  def arrival_date
    return @m_connections.last.arrival_date
  end
  def arrival
    return @m_connections.last.arrival
  end

  def duration
    a_days = (Date.parse(arrival_date) - Date.parse(departure_date)).to_i
    c_duration = departure.duration_to(arrival)
    c_duration.add(SimpleTime.new(a_days*24,0))
    return c_duration
  end

  def to_s
    via = @m_flight.hops
    via.shift
    via.pop
    return "Duration: "+duration.to_s+" From " + from.city.to_s + " on "+departure_date.to_s+" "+departure.to_s+ " to "+destionation.city.to_s+" on " + arrival_date.to_s + " "+arrival.to_s + (via.empty? ? "" : "  via ("+via.join(",")+")")
  end
end
